package com.android.view.adapter.base;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.android.view.fragment.info.ExchangeFragment;
import com.android.view.fragment.info.MainFragment;
import com.android.view.fragment.info.MargeTradeFragment;
import com.android.view.fragment.info.MarketsFragment;
import com.android.view.fragment.info.UserFragment;

import java.util.List;

/**
 * Created by TenFace
 * on 2017/8/23.
 */

public class BaseFragmentPageAdapter extends FragmentStatePagerAdapter {
    private List<Fragment> fragmentList;

    public BaseFragmentPageAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        fragmentList = fragments;
    }


    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList == null ? 0 : fragmentList.size();
    }

    @Override
    public int getItemPosition(Object object) {
        if (object.getClass().getName().equals(MainFragment.class.getName())
                || object.getClass().getName().equals(MarketsFragment.class.getName())
                || object.getClass().getName().equals(ExchangeFragment.class.getName())
                || object.getClass().getName().equals(MargeTradeFragment.class.getName())
                || object.getClass().getName().equals(UserFragment.class.getName())) {
            return POSITION_NONE;
        }
        return super.getItemPosition(object);
    }
}
